/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hhf.flex.ascreator;

import hhf.flex.ascreator.exceptions.IgnoredClassException;
import hhf.flex.ascreator.exceptions.IllegalClassException;
import hhf.flex.ascreator.exceptions.NoAnnotationClassException;
import hhf.flex.ascreator.exceptions.NoCommentClassException;
import hhf.flex.ascreator.exceptions.NoSuperClassException;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

/**
 *
 * @author HHFrancois
 */
public class ASEnumCreator extends ASCreator {

	private Class _class;

	public ASEnumCreator(String path, Class clazz, Map<String, Object> options) {
		super(path, options);
		this._class = clazz;
	}

	@Override
	protected String getASPackage() {
		return _class.getPackage().getName();
	}

	@Override
	protected void checkClass() throws IllegalClassException, IgnoredClassException {
	}

	@Override
	protected boolean isInterface() {
		return false;
	}

	@Override
	protected String getASClassName() {
		return this._class.getSimpleName();
	}

	@Override
	protected String getASSuperClassName() throws NoSuperClassException {
		throw new NoSuperClassException();
	}

	@Override
	protected Collection<String> getASInterfacesName() {
		return null;
	}

	@Override
	protected Set<String> getASImports() {
		return null;
	}

	@Override
	protected Collection<String> getASClassAnnotations() throws NoAnnotationClassException{
		throw new NoAnnotationClassException();
	}

	@Override
	protected Map<String, String> getASEvents() {
		return null;
	}

	@Override
	protected Set<String> getASNamespaces() {
		return null;
	}

	@Override
	protected void writeASBodyConstructor(OutputStreamWriter out) throws IOException {
	}

	@Override
	protected void writeASFieldsAndMethods(OutputStreamWriter out) throws IOException {
		for (Object c : _class.getEnumConstants()) {
			Enum enumC = (Enum) c;
			inserASField(out, enumC.name(), "String");
		}
		out.write("\t\tpublic static function get enumConstants():Array {\n");
		// Ecrit le corp de la methode
		out.write("\t\t\treturn [");
		for (int i=0; i<_class.getEnumConstants().length; i++) {
			Enum enumC = (Enum) _class.getEnumConstants()[i];
			out.write("\""+enumC.name()+"\"");
			if(i<_class.getEnumConstants().length -1)
				out.write(", ");
		}
		out.write("];\n");
		out.write("\t\t}\n\n");
	}

	private void inserASField(OutputStreamWriter out, String fieldName, String fieldType) throws IOException {
		out.write("\t\tpublic static const " + fieldName + ":" + fieldType + " = \""+fieldName+"\";\n\n");
	}

	@Override
	protected String getASClassComment() throws NoCommentClassException {
		throw new NoCommentClassException();
	}

	@Override
	protected void createSeeAlsoASClass() {
	}
}
